﻿namespace DeltaGroup.WheelOfJeopardy.UI.Screens
{
    using System.Windows;
    using System.Windows.Controls;
    using System.Windows.Media;

    using DeltaGroup.WheelOfJeopardy.Model;

    /// <summary>
    /// Interaction logic for ChallengeBlock.xaml
    /// </summary>
    public partial class ChallengeBlock : UserControl
    {
        #region Fields

        public static readonly DependencyProperty DebugModeProperty = DependencyProperty.Register("DebugMode", typeof(bool), typeof(ChallengeBlock), new PropertyMetadata(false, new PropertyChangedCallback(DebugMode_Changed)));

        #endregion Fields

        #region Constructors

        /// <summary>
        /// Initializes a new instance of the <see cref="ChallengeBlock"/> class.
        /// </summary>
        public ChallengeBlock()
        {
            InitializeComponent();
        }

        #endregion Constructors

        #region Properties

        /// <summary>
        /// Gets or sets a value indicating whether [debug mode].
        /// </summary>
        /// <value><c>true</c> if [debug mode]; otherwise, <c>false</c>.</value>
        public bool DebugMode
        {
            get { return (bool)GetValue(DebugModeProperty); }
            set { SetValue(DebugModeProperty, value); }
        }

        #endregion Properties

        #region Methods

        /// <summary>
        /// Debugs the mode_ changed.
        /// </summary>
        /// <param name="sender">The sender.</param>
        /// <param name="args">The <see cref="System.Windows.DependencyPropertyChangedEventArgs"/> instance containing the event data.</param>
        private static void DebugMode_Changed(DependencyObject sender, DependencyPropertyChangedEventArgs args)
        {
            var block = sender as ChallengeBlock;
            var challenge = (block.DataContext as Challenge);

            if ((bool)args.NewValue == true && challenge is DailyDouble)
            {
                block.ChallengeBackground.Fill = Brushes.Red;
                block.PointTextBlock.Text = "DD";
            }
        }

        /// <summary>
        /// Handles the MouseLeftButtonUp event of the ChallengeBlock control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="System.Windows.Input.MouseButtonEventArgs"/> instance containing the event data.</param>
        private void ChallengeBlock_MouseLeftButtonUp(object sender, System.Windows.Input.MouseButtonEventArgs e)
        {
            if (DebugMode)
            {
                var block = sender as ChallengeBlock;
                var challenge = block.DataContext as Challenge;

                challenge.IsChallenged = true;
            }
        }

        #endregion Methods
    }
}